package com.itany.corejava.code07_面向对象;

import java.util.Scanner;

/**
 * @author: 石小俊
 * @date: 2023年03月06日 15:06
 * @version: 1.0
 */
public class Account {
    // 全局变量,即成员属性
    String name;
    double money;
    int age;

    // 定义在方法参数中的局部变量name
    public void test(String name) {
        // 此时访问的name是局部变量
        System.out.println(name);
        // 方法中的局部变量
        double money = 10000;
        // 此时必须为变量赋值后才能访问,否则报错
        System.out.println(money);
        System.out.println("全局变量name:" + this.name + ",全局变量money:" + this.money);
        System.out.println("局部变量name:" + name + ",局部变量money:" + money);
        System.out.println("全局变量age:" + age);
    }

    // 查询余额, 打印出户主姓名与账户余额
    public void queryMoney() {
        System.out.println("姓名:" + name + ",余额:" + money);
    }

    // 存钱,打印存储了多少钱,存储后账户的余额
    public void saveMoney(double money) {
        this.money += money;
        System.out.println("您存储了" + money + "元,当前账户余额为:" + this.money);
    }

    // 转账,打印谁给你转账,转了多少钱,转账后余额
    public void transfer(String name, double money) {
        this.money += money;
        System.out.println(name + "向您转账了" + money + "元,当前账户余额为:" + this.money);
    }

    // 取钱,打印取出了多少钱,剩余的余额是多少
    public void getMoney(double money) {
        this.money -= money;
        System.out.println("您提取了" + money + "元,当前账户余额为:" + this.money);
    }

    public void showMenu(){
        Scanner sc = new Scanner(System.in);
        System.out.println("--------------------------");
        System.out.println("欢迎使用账户管理系统,该系统提供以下功能:");
        System.out.println("1.查询余额 2.存钱 3.转账 4.取钱 5.退出");
        while (true){
            System.out.println("--------------------------");
            System.out.print("请选择您需要办理的业务:");
            int choice = sc.nextInt();
            switch (choice){
                case 1:
                    queryMoney();
                    break;
                case 2:
                    System.out.print("请输入您存储的金额:");
                    double money = sc.nextDouble();
                    saveMoney(money);
                    break;
                case 3:
                    System.out.print("谁向您转账:");
                    String name = sc.next();
                    System.out.print("转账金额为:");
                    money = sc.nextDouble();
                    transfer(name,money);
                    break;
                case 4:
                    System.out.print("请输入提取的金额:");
                    money = sc.nextDouble();
                    getMoney(money);
                    break;
                case 5:
                    System.out.println("您已经退出,欢迎再次使用");
                    return;
            }
        }
    }

}

class TestAccount {
    public static void main(String[] args) {
        Account account = new Account();
        account.name = "admin";
        account.money = 5000.0;
//        account.test("jack");

        account.showMenu();

    }
}
